﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using System.Web.Security;

namespace Marketplace.WebForm.Generator
{
    public class Profile: ProfileBase
    {
        private ProfileBase _profile = null;
        private Profile(ProfileBase profile)
        {
            _profile = profile;
        }
        public static Profile  Current 
        {
            get 
            {
                var membershipUser = Membership.GetUser();
                return (Profile)Create(membershipUser.UserName);  //Is Create() Singletone?@@@@@@@@@@@@@@
            }
        }

        public static Profile CreateProfile(string userName)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                return null;
                
            }
            return new Profile(Create(userName));   //Different with  @@@@@@@@@@@@ ?
        }

        private const string TelephoneName = "Telephone";
        private const string MobileName = "Mobile";
        private const string AddressName = "Address";

        public string Telephone
        {
            get
            {
                return (string)_profile.GetPropertyValue(TelephoneName);
            }
            set
            {
                _profile.SetPropertyValue(TelephoneName,value);
            }
        }

        public string  Mobile 
        {
            get
            {
                return (string)_profile.GetPropertyValue(MobileName);
            }
            set
            {
                _profile.SetPropertyValue(TelephoneName,value);
            }
        }

        public string Address 
        {
            get
            {
                return (string)_profile.GetPropertyValue(AddressName);
            }
            set 
            {
                _profile.SetPropertyValue(AddressName,value);
            }
        }

        public override void Save()
        {
            _profile.Save();              //reson
        }

    }
}